package com.kitten.oss.biz.config;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Slf4j
@Configuration
public class AliOssConfig {
    @Resource
    private AliOssProperties aliOssProperties;


    @Bean
    public OSS aliyunOSSClient() {
        // 设置访问凭证
        DefaultCredentialProvider credentialsProvider = CredentialsProviderFactory.newDefaultCredentialProvider(
                aliOssProperties.getAccessKey(), aliOssProperties.getSecretKey());
        log.info("aliyunOSSClient init success accessKey:{}, secretKey:{}", aliOssProperties.getAccessKey(), aliOssProperties.getSecretKey());
        // 创建 OSSClient 实例
        return new OSSClientBuilder().build(aliOssProperties.getEndpoint(), credentialsProvider);
    }

}
